package com.kelvin.manage.controller;

import com.kelvin.manage.common.CommonResult;
import com.kelvin.manage.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult register(@RequestParam String username,
                                 @RequestParam String password,
                                 @RequestParam String confirmPassword,
                                 @RequestParam String role) {
        int result=userService.register(username, password,confirmPassword,role);
        if(result==1){
            return new CommonResult(200,"注册成功",null);}
        else{
            return new CommonResult(500,"注册失败",null);}
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult login(@RequestParam String username,
                              @RequestParam String password) {
        int result=userService.login(username, password);
        if(result==1){
        return new CommonResult(200,"登录成功",null);}
        else{
        return new CommonResult(500,"登录失败",null);}
    }


}
